<?php

/* @var $factory \Illuminate\Database\Eloquent\Factory */

use App\Model;
use App\Models\Asset;
use App\Models\AssetStock;
use App\Models\FilterableAssetBundle\FilterableAssetBundle;
use App\Models\FilterableAssetBundle\FilterableAssetBundleCriterion;
use App\Models\User;
use Faker\Generator as Faker;


$factory->define(FilterableAssetBundle::class, function (Faker $faker) {
    $user = User::find(1);
    return [
        "name" => $faker->name,
        "description" => $faker->word,
        "created_by" => $user->id
    ];
});

$factory->define(FilterableAssetBundleCriterion::class, function (Faker $faker) {
    $model = $faker->randomElement([Asset::class, AssetStock::class]);
    $asset = factory($model)->create();
    $name = $faker->randomElement(['name', 'category']);
    $isNameField = $name == 'name';
    $value = $isNameField ? $asset->name : $asset->category->name;
    return [
        "asset_type" => $model,
        "field_name" => $name,
        "field_value" => $value,
        "operator" => $faker->randomElement(['=', 'like']),
        "quantity" => $isNameField ? 1 : 2
    ];
});

